home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Programming / ace_gpl_release / src / ace / c / acedef.h next >
Encoding:
C/C++ Source or Header  |  1998-10-04  |  14.6 KB  |  789 lines

  1. /* << ACE >> 
  2.  
  3.    -- Amiga BASIC Compiler --
  4.  
  5.    ** #includes, #defines and function prototypes ** 
  6.    ** Copyright (C) 1998 David Benn
  7.    ** 
  8.    ** This program is free software; you can redistribute it and/or
  9.    ** modify it under the terms of the GNU General Public License
  10.    ** as published by the Free Software Foundation; either version 2
  11.    ** of the License, or (at your option) any later version.
  12.    **
  13.    ** This program is distributed in the hope that it will be useful,
  14.    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.    ** GNU General Public License for more details.
  17.    **
  18.    ** You should have received a copy of the GNU General Public License
  19.    ** along with this program; if not, write to the Free Software
  20.    ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    Author: David J Benn
  23.      Date: 19th October-30th November, 3rd-12th December 1991,
  24.        14th,27th January 1992, 5th,7th-17th, 
  25.            23rd-24th February 1992,
  26.            14th,22nd March 1992,
  27.        21st April 1992,
  28.        2nd,11th,15th May 1992,
  29.        7th,8th,9th,11th,13th,14th,28th June 1992,
  30.        2nd-6th,8th,14th-19th,26th,28th,29th July 1992,
  31.        1st,9th August 1992,
  32.        6th,28th December 1992,
  33.        7th January 1993,
  34.        11th,13th February 1993,
  35.        1st,6th March 1993,
  36.        12th April 1993,
  37.        17th May 1993,
  38.        12th,14th June 1993,
  39.        1st July 1993,
  40.        5th,25th September 1993,
  41.        26th October 1993,
  42.        6th,15th November 1993,
  43.        17th,18th,24th December 1993,
  44.        2nd,3rd,7th,9th January 1994,
  45.        6th,15th,16th,27th February 1994,
  46.        10th,14th July 1994,
  47.        11th September 1994,
  48.        13th May 1996,
  49.        4th,22nd June 1996,
  50.        4th September 1996
  51. */
  52.  
  53. #include <exec/types.h>
  54. #include <exec/memory.h>
  55. #include <libraries/mathffp.h>
  56. #include <libraries/mathlibrary.h>
  57. #include <libraries/dos.h>
  58. #include <stdio.h>
  59.  
  60. /* AmigaBASIC reserved words */
  61. enum {     abssym = 0,
  62.     allsym,        
  63.     andsym,        
  64.     appendsym,      
  65.     areasym,      
  66.     areafillsym,     
  67.     assym,          
  68.     ascsym,         
  69.     atnsym,         
  70.     basesym,        
  71.     beepsym,      
  72.     breaksym,     
  73.     callsym,      
  74.     cdblsym,      
  75.     chainsym,    
  76.     chdirsym,     
  77.     chrstrsym,     
  78.     cintsym,      
  79.     circlesym,     
  80.     clearsym,    
  81.     clngsym,      
  82.     closesym,     
  83.     clssym,      
  84.     collisionsym,    
  85.     colorsym,     
  86.     commonsym,    
  87.     contsym,      
  88.     cossym,      
  89.     csngsym,      
  90.     csrlinsym,     
  91.     cvdsym,        
  92.     cvisym,        
  93.     cvlsym,        
  94.     cvssym,        
  95.     datasym,      
  96.     datestrsym,     
  97.     declaresym,     
  98.     defsym,      
  99.     defdblsym,     
  100.     defintsym,     
  101.     deflngsym,     
  102.     defsngsym,     
  103.     defstrsym,     
  104.     deletesym,     
  105.     dimsym,      
  106.     elsesym,      
  107.     elseifsym,     
  108.     endsym,      
  109.     eofsym,      
  110.     eqvsym,      
  111.     erasesym,     
  112.     erlsym,      
  113.     errsym,      
  114.     errorsym,     
  115.     exitsym,      
  116.     expsym,      
  117.     fieldsym,    
  118.     filessym,    
  119.     fixsym,      
  120.     fnsym,          
  121.     forsym,          
  122.     fresym,      
  123.     functionsym,     
  124.     getsym,      
  125.     gosubsym,     
  126.     gotosym,      
  127.     hexsym,      
  128.     ifsym,          
  129.     impsym,      
  130.     inkeysym,     
  131.     inputsym,     
  132.     inputstrsym,    
  133.     instrsym,     
  134.     intsym,      
  135.     killsym,      
  136.     lboundsym,      
  137.     leftstrsym,     
  138.     lensym,      
  139.     letsym,      
  140.     librarysym,     
  141.     linesym,      
  142.     listsym,        
  143.     llistsym,    
  144.     loadsym,        
  145.     locsym,      
  146.     locatesym,     
  147.     lofsym,      
  148.     logsym,      
  149.     lpossym,      
  150.     lprintsym,     
  151.     lsetsym,        
  152.     menusym,      
  153.     mergesym,    
  154.     midstrsym,     
  155.     mkdstrsym,    
  156.     mkistrsym,    
  157.     mklstrsym,    
  158.     mksstrsym,    
  159.     modsym,      
  160.     mousesym,     
  161.     namesym,      
  162.     newsym,        
  163.     nextsym,      
  164.     notsym,      
  165.     objaxsym,    
  166.     objaysym,    
  167.     objclipsym,    
  168.     objclosesym,    
  169.     objhitsym,    
  170.     objoffsym,    
  171.     objonsym,    
  172.     objplanessym,    
  173.     objprioritysym,    
  174.     objshapesym,    
  175.     objstartsym,    
  176.     objstopsym,    
  177.     objvxsym,    
  178.     objvysym,    
  179.     objxsym,        
  180.     objysym,        
  181.     octstrsym,     
  182.     offsym,      
  183.     onsym,          
  184.     opensym,        
  185.     optionsym,    
  186.     orsym,          
  187.     outputsym,    
  188.     paintsym,     
  189.     palettesym,     
  190.     patternsym,     
  191.     peeksym,      
  192.     peeklsym,     
  193.     peekwsym,     
  194.     pointsym,     
  195.     pokesym,      
  196.     pokelsym,     
  197.     pokewsym,     
  198.     possym,      
  199.     presetsym,     
  200.     printsym,     
  201.     psetsym,      
  202.     ptabsym,      
  203.     putsym,      
  204.     randomizesym,     
  205.     readsym,      
  206.     remsym,      
  207.     restoresym,     
  208.     resumesym,    
  209.     returnsym,     
  210.     rightstrsym,     
  211.     rndsym,      
  212.     rsetsym,        
  213.     runsym,        
  214.     saddsym,      
  215.     savesym,        
  216.     saysym,      
  217.     screensym,     
  218.     scrollsym,     
  219.     sgnsym,      
  220.     sharedsym,     
  221.     sinsym,      
  222.     sleepsym,     
  223.     soundsym,     
  224.     spacestrsym,     
  225.     spcsym,      
  226.     sqrsym,      
  227.     staticsym,     
  228.     stepsym,      
  229.     sticksym,     
  230.     stopsym,      
  231.     strstrsym,     
  232.     strigsym,     
  233.     stringstrsym,    
  234.     subsym,      
  235.     swapsym,      
  236.     systemsym,     
  237.     tabsym,      
  238.     tansym,      
  239.     thensym,      
  240.     timestrsym,     
  241.     timersym,     
  242.     tosym,          
  243.     translatestrsym, 
  244.     troff,        
  245.     tron,        
  246.     uboundsym,    
  247.     ucasestrsym,     
  248.     usingsym,     
  249.     valsym,      
  250.     varptrsym,     
  251.     waitsym,      
  252.     wavesym,      
  253.     wendsym,      
  254.     whilesym,     
  255.     widthsym,     
  256.     windowsym,     
  257.     writesym,     
  258.     xorsym,
  259.  
  260. /* ACE-specific reserved words */
  261.     addresssym,
  262.     allocsym,
  263.     argstrsym,
  264.     argcountsym,
  265.     assemsym,
  266.     backsym,
  267.     bevelboxsym,
  268.     binstrsym,
  269.     blocksym,
  270.     buttonsym,
  271.     bytesym,
  272.     casesym,
  273.     constsym,
  274.     cstrsym,
  275.     daysym,    
  276.     externalsym,
  277.     fileboxstrsym,
  278.     fontsym,    
  279.     forwardsym,
  280.     gadgetsym,
  281.     globalsym,
  282.     handlesym,
  283.     headingsym,
  284.     homesym,    
  285.     iffsym,    
  286.     inputboxsym,
  287.     inputboxstrsym,
  288.     longintsym,
  289.     messagesym,    
  290.     msgboxsym,    
  291.     pendownsym,    
  292.     penupsym,    
  293.     potxsym,    
  294.     potysym,    
  295.     printssym,    
  296.     repeatsym,    
  297.     serialsym,    
  298.     setheadingsym,    
  299.     setxysym,    
  300.     shlsym,        
  301.     shortintsym,    
  302.     shrsym,        
  303.     singlesym,    
  304.     sizesym,    
  305.     sizeofsym,
  306.     stringsym,
  307.     structsym,    
  308.     stylesym,    
  309.     turnsym,    
  310.     turnleftsym,
  311.     turnrightsym,
  312.     turtlesym,    
  313.     untilsym,    
  314.     xcorsym,    
  315.     ycorsym,    
  316.  
  317.     RWSENTINEL };
  318.  
  319. /* special symbols */
  320. enum {    increment =    500,
  321.     decrement,
  322.     shortpointer,    
  323.     longpointer,
  324.     singlepointer,
  325.     memberpointer,
  326.     plus,
  327.     minus,
  328.     multiply,
  329.     fdiv,
  330.     idiv,
  331.     raiseto,
  332.     lparen,
  333.     rparen,
  334.     comma,
  335.     apostrophe,
  336.     semicolon,
  337.     becomes,
  338.     colon,
  339.     question,
  340.     notequal,
  341.     ltorequal,     
  342.     gtorequal,
  343.     equal,
  344.     lessthan,
  345.     gtrthan,
  346.     hash,
  347.     octalprefix,
  348.     hexprefix,
  349.     atsymbol,
  350.     endofline,
  351.  
  352.     RSSENTINEL };
  353.  
  354. /* symbols */
  355. enum {    shortconst =     1000,
  356.     longconst,
  357.     singleconst,
  358.     doubleconst,
  359.     stringconst,
  360.     ident };
  361.  
  362. /* types */
  363. enum {    bytetype =     2000,
  364.     shorttype,
  365.     longtype,
  366.     singletype,
  367.     doubletype,
  368.     stringtype,
  369.     notype };
  370.  
  371. /* objects */
  372. enum {    variable =     3000,
  373.     array,
  374.     subprogram,
  375.     definedfunc,
  376.     function,
  377.     extfunc,
  378.     extvar,
  379.     label,
  380.     constant,
  381.     structdef,
  382.     structure,
  383.     rsvd_word,
  384.  
  385.     undefined =      9999 };
  386.  
  387. #define    MAXLINELEN   1024          /* max length of a BASIC line */
  388. #define    MAXIDSIZE     42           /* max length of identifier (+ qualifier) */
  389. #define    MAXSTRLEN   1024           /* max length of string */
  390. #define    MAXSHORT   32767           /* max +ve short value */
  391. #define    MINSHORT  -32768           /* min -ve short value */
  392. #define    MAXLONG    2147483647      /* max +ve long value */
  393. #define    MINLONG   -2147483648      /* min -ve long value */ 
  394. #define    MAXPARAMS     40           /* max # of subprogram parameters */
  395. #define    NEGATIVE      -1       /* a negative result from ACE lib check */
  396. #define    MAXCASES     1000         /* max # of cases in a CASE statement */
  397. #define    NUMACELIBS     7       /* # of shared libraries used by ACE */
  398. #define    NUMLIBS          40       /* max # of "other" shared libraries */
  399. #define    LF_CODE           0       /* line feed code for PRINTS */
  400. #define    TAB_CODE       1       /* tab code for PRINTS */
  401. #define    SPACE_CODE     2       /* single space code for PRINTS */
  402.  
  403. /* --symbol table-- */
  404. #define    ZERO        0
  405. #define    ONE         1
  406. #define    fwdref      0
  407. #define    subdecl     1
  408. #define    undeclared  2       /* undeclared string variable (eg: x$="A")*/    
  409. #define    declared    3       /* string variable declared with STRING */
  410. #define    MAXDIMS   255
  411.  
  412. /* --symbol table-- */
  413. typedef union conststruct {
  414.                SHORT shortnum;    
  415.                LONG  longnum;
  416.                float singlenum;
  417.               } CONST;
  418.  
  419. typedef struct structmem {
  420.               char  name[MAXIDSIZE];
  421.               int   type;
  422.               ULONG offset;
  423.               ULONG strsize;
  424.               struct structmem *next;
  425.              } STRUCM;
  426.   
  427. typedef struct symstruct {
  428.               char   *name;              /* name of identifier */
  429.               int    type;               /* type (short,long...) */
  430.               int    object;             /* variable,sub... */
  431.               int    dims;               /* # of array elements */
  432.               BOOL   shared;         /* is object shared? */
  433.               BOOL   new_string_var;     /* new string variable? */
  434.               SHORT  *index;              /* array indices */
  435.               SHORT     no_of_params;       /* # of SUB parameters */
  436.               int     p_type[MAXPARAMS];  /* SUB parameter types */
  437.               UBYTE  decl;             /* forward reference? */
  438.               UBYTE  *reg;                  /* lib function regs */
  439.               char   *libname;         /* library name */
  440.               CONST  numconst;         /* a numeric constant */
  441.               STRUCM *structmem;         /* structdef list ptr */
  442.               int    address;            /* frame/library offset */
  443.               ULONG  size;             /* # of bytes in object */
  444.               int    level;              /* main or sub program */
  445.               struct symstruct *other;   /* for cross-reference */
  446.               struct symstruct *next;    /* next table entry */
  447.                  } SYM;
  448.  
  449. /* --code generator-- */
  450.  
  451. /* --code list-- */
  452. typedef struct codelist {
  453.              char *opcode;          /* 68000 opcode */ 
  454.              char *srcopr;          /* source operand */
  455.              char *destopr;         /* destination operand */
  456.              struct codelist *next;
  457.             } CODE;
  458.  
  459. /* --data list-- */
  460. typedef struct datalist {
  461.              char *name;            /* name of storage */
  462.              char *literal;         /* data */
  463.              struct datalist *next;
  464.             } DATA;
  465.  
  466. /* --bss list-- */
  467. typedef struct bsslist {
  468.              char *name;            /* name of storage */
  469.              char *store;       /* storage type & size */
  470.              struct bsslist *next;
  471.                } BSS;
  472.  
  473. /* --XREF list-- */
  474. typedef struct xreflist {
  475.              char *name;           /* name of external reference */
  476.              struct xreflist *next;
  477.             } XREF;
  478.  
  479. /* --BASIC DATA list-- */
  480. typedef struct basicdatalist {
  481.              char *literal; /* string or float constant */
  482.              struct basicdatalist *next;
  483.             } BASDATA;
  484.  
  485. /* --ACE library usage information-- */
  486. typedef struct aceliblist {
  487.                char name[MAXIDSIZE];   /* library name */
  488.                char base[MAXIDSIZE+5]; /* library base: _NAMEBase */
  489.               } ACELIBS;
  490.  
  491. /* --function protos-- */
  492.  
  493. /* opt.c */
  494. BOOL     is_a_move();
  495. SHORT    peephole();
  496. void    optimise();
  497.  
  498. /* lex.c */
  499. void    open_shared_libs();
  500. void    close_shared_libs();
  501. void     setup();
  502. void    cleanup();
  503. void    _warn();
  504. void    _error();
  505. void    _abort();
  506. void    open_files();
  507. void    nextch();
  508. BOOL    letter();
  509. BOOL    digit();
  510. BYTE    hex_digit();
  511. BYTE    octal_digit();
  512. BOOL    qualifier();
  513. void    convert_special_ident();
  514. BOOL    ssymbol();
  515. int    rsvd_wd();
  516. int    rsvd_sym();
  517. void     reclassify_number();
  518. void    classify_integer();
  519. void    insymbol();
  520. void    showsym();
  521. void     showobj();
  522. void    showtyp();
  523. void    tab();
  524. void    cr();
  525. void    lf();
  526.  
  527. /* alloc.c */
  528. void    *alloc();
  529. void    free_alloc();
  530. void    *sym_alloc();
  531. void    free_sym_alloc();
  532. CODE    *alloc_code();
  533. void    free_code();
  534. BOOL    alloc_code_members();
  535. void    free_code_members();
  536.  
  537. /* sym.c */
  538. void    new_symtab();
  539. void    kill_symtab();
  540. void    find_tab_tail();
  541. BOOL    exist();
  542. void    enter();
  543. void    create_lists();
  544. BOOL    is_a_label();
  545. void    write_code();
  546. BOOL    label_undef();
  547. void    undef_label_check();
  548. void    kill_code();
  549. void    gen();
  550. void    change();
  551. BOOL    exist_DATA();
  552. void    enter_DATA();
  553. void    write_data();
  554. BOOL    exist_BSS();
  555. void    enter_BSS();
  556. void    write_bss();
  557. BOOL    exist_XREF();
  558. void    enter_XREF();
  559. void    write_xrefs();
  560. void    enter_BASDATA();
  561. void    write_basdata();
  562. void    find_structmem_tail();
  563. BOOL    structmem_exist();
  564. void    add_struct_member();
  565.  
  566. /* basfun.c */
  567. BOOL    strfunc();
  568. int    stringfunction();
  569. int    gen_single_func();
  570. BOOL    numfunc();
  571. int    numericfunction();    
  572. int      address_of_object();
  573. int      find_object_size();
  574.  
  575. /* functions in main ace modules */
  576. void    make_temp_long();
  577. void    make_temp_short();
  578. void    make_temp_string();
  579. void    make_string_const();
  580.  
  581. void    make_label_from_linenum();
  582.  
  583. LONG    max_array_ndx();
  584. void    push_indices();
  585. void    get_abs_ndx();
  586.  
  587. void    push_num_constant();
  588. int    push_struct();
  589.  
  590. void    assem();
  591. void    parse_option_list();
  592.  
  593. BOOL    factorfunc();
  594. int    factor();
  595. BOOL    coerce();
  596.  
  597. void    make_short();
  598. void    make_long();
  599.  
  600. int    ptr_term();
  601. int    expterm();
  602. int    negterm();
  603. int    prodterm();
  604. int    idivterm();
  605. int    modterm();
  606. int    simple_expr();
  607. BOOL    relop();
  608. char    *cond_branch_op();
  609. void    make_label();
  610. int    relexpr();
  611. int    notexpr();
  612. int    andexpr();
  613. int    orexpr();
  614. int    eqvexpr();
  615. int    expr();
  616.  
  617. void    pop_operands();
  618. void    push_result();
  619.  
  620. void    gen_round();
  621. void    gen_Flt();
  622. void    change_Flt();
  623.  
  624. int    make_integer();
  625. int    assign_coerce();
  626. void    make_string_store();
  627. void    create_string_variable();
  628. void    assign_to_string_variable();
  629. void    assign_to_string_array();
  630. void    assign_to_struct();
  631. void    assign();
  632.  
  633. void    make_array_name();
  634. void    dim();
  635.  
  636. void    gen_printcode();
  637. void    print_statement();
  638. void    gen_printscode();
  639. void    prints_statement();
  640.  
  641. void    block_if();
  642. void    if_statement();
  643. void    while_statement();
  644. void    repeat_statement();
  645. void    case_statement();
  646. int    for_assign();
  647. void    for_statement();
  648. void    gen_branch();
  649. void    on_branch();
  650. void    block_statement();
  651.  
  652. void    make_sure_short();
  653. void    make_sure_long();
  654.  
  655. void    pset();
  656. void    paint();
  657. void    circle();
  658. void    draw_line();
  659. void    color();
  660. void    text_style();
  661. void    text_font();
  662. void    gfx_get();
  663. void    gfx_put();
  664.  
  665. void    input();
  666. void    point_to_array();
  667. void    make_data_const();
  668. void    get_data();
  669. void    read_data();
  670.  
  671. void    change_id_type();
  672.  
  673. void    screen();
  674. void    scroll();
  675.  
  676. void    window();
  677. void    wdwclose();
  678. void    wdwoutput();
  679.  
  680. void    gadget_rectangle();
  681. void    gadget();
  682. void    wait_gadget();
  683. void    modify_gadget();
  684. void    close_gadget();
  685. void    bevel_box();
  686.  
  687. void    MsgBox();
  688.  
  689. void    clear_menu();
  690. void    wait_menu();
  691. void    menu();
  692.  
  693. void    open_a_file();
  694. void    close_a_file();
  695. void    line_input();
  696. void    write_to_file();
  697. void    gen_writecode();
  698. void    print_to_file();
  699. void    input_from_file();
  700. void    kill();
  701. void    rename();
  702. void    chdir();
  703. void    files();
  704.  
  705. void    serial_command();
  706. void    open_serial();
  707. void    close_serial();
  708. void    read_serial();
  709. void    write_serial();
  710. void    name_serial();
  711.  
  712. void    message();
  713. void    message_open();
  714. void    message_close();
  715. void    message_read();
  716. void    message_write();
  717. void    message_wait();
  718. void    message_clear();
  719.  
  720. void    iff();
  721. void    iff_open();
  722. void    iff_read();
  723. void    iff_close();
  724.  
  725. BYTE     check_for_ace_lib();
  726. void    enter_new_library();
  727. void    make_library_base();    
  728. void    make_library_name();    
  729. void    make_bmap_name();
  730. void    get_libname();
  731. void    library();
  732. void    closelibrary();
  733. void    remove_qualifier();
  734. BOOL    search_func();
  735. BOOL    found_func();
  736. void    declare();
  737.  
  738. void     load_func_params();
  739. void     load_mc_params();
  740.  
  741. void    sound();
  742.  
  743. void    get_event_trap_label();
  744. void    change_event_trapping_status();
  745. void    check_for_event();
  746. void    ctrl_c_test();
  747. void    break_event_test();
  748. void    menu_event_test();
  749. void    mouse_event_test();
  750. void    timer_event_test();
  751. void    error_event_test();
  752. void    wdw_close_test();
  753. void     wdw_event_test();
  754. void    gad_event_test();
  755.  
  756. void    define_structure();
  757. void    declare_structure();
  758. void    define_constant();
  759. void    declare_variable();
  760. void    define_external_object();
  761. void    define_external_variable();
  762. void    define_external_function();
  763.  
  764. void    call_external_function();
  765.  
  766. void    poke();
  767. void    pokew();
  768. void    pokel();
  769. void    get_obj_info();
  770. void    swap();
  771.  
  772. void    handle_label();
  773. void    statement();
  774.  
  775. void    forward_ref();
  776. void    load_params();
  777. void    sub_params();
  778. void    parse_shared_vars();
  779.  
  780. void    block();
  781. void    parse();
  782. void    compile();
  783.  
  784. void    show_title();
  785. void    usage();
  786. BOOL    check_options();
  787. void    dump_reserved_words();
  788. void    main();
  789.